<?

/*	Media.image OBJECT
*	Comment here
*
*					*/


class MediaImage extends MOD {

	function __construct( $vars ) {
		$this->_addvars( $vars );
		$this->_ref(); 
	
	}
	
	function output () {
		
		if( $this->action )
			$result = $this->{ "filter_" . $this->action }();
		 
		return ( $this->vars->imgid || $this->window )? $this->parse( $result ) : $result;
		
	}
	
/*	PARSE FUNCTIONALITIES
*	parse_meta builds the flashVars attribute, 
*	based on a variable json_object
*
*	parse_external builds the external source string
*					*/
	function filter_single () {
		
		if( !$this->vars->img && !$this->vars->imgid && $_GET[ "id" ])
			$this->vars->imgid = (int) $_GET[ "id" ];
		
		$IMG = new MEDIA( $this->vars );
		return $IMG->_img();
	}



	function filter_group () {
		global $DB;
		
		
		if( $this->vars->dyn )
			$this->vars->parentid = $this->parse_dyn_id( $this->vars->dyn );
		
		
		if( !empty($this->vars->parentid) && $group = $DB->reference( "group.img", (int) $this->vars->parentid, "media.img" ))
			
			$i = 0;
			foreach( $group as $img ) {
				$this->vars->imgid = (int) $img;
				$IMG	= new MEDIA( $this->vars );
				$body[]	= $IMG->_img();
				
				$i++;
				if ( !empty($this->vars->limit) ) {
					if ($i == $this->vars->limit) break;
				}
			}
	
		return implode( "\n", $body );
	}
	
	
	function parse_dyn_id( $dyn ) {
		global $DB, $Object;
		
	
		if( $dyn == "ref" ) {
			$refs = $DB->reference(( $Object )? $Object->type : $this->vars->type, (int)( $Object )? $Object->id : $this->vars->id, $this->vars->objtype );
			$id = $refs[ 0 ];
		}
		return (int) $id;
	}
	
} 

?>